package whisper.common.support.response;

import java.util.HashMap;

/**
 * Created by JT on 2018/4/10
 */
public class WebResponse extends HashMap {


    public WebResponse ok() {
        return ok(WebResponseCode.MESSAGE_SUCCESS);
    }

    public WebResponse ok(String message) {
        this.put(WebResponseCode.KEY_CODE, WebResponseCode.CODE_SUCCESS);
        this.put(WebResponseCode.KEY_MESSAGE, message);
        return this;
    }

    public WebResponse failed() {
        return failed(WebResponseCode.MESSAGE_FAILED);
    }

    public WebResponse failed(String message) {
        this.put(WebResponseCode.KEY_CODE, WebResponseCode.CODE_FAILED);
        this.put(WebResponseCode.KEY_MESSAGE, message);
        return this;
    }

    public WebResponse errer() {
        return errer(WebResponseCode.MESSAGE_ERROR);
    }

    public WebResponse errer(String message) {
        this.put(WebResponseCode.KEY_CODE, WebResponseCode.CODE_ERROR);
        this.put(WebResponseCode.KEY_MESSAGE, message);
        return this;
    }

    public WebResponse withData(Object data) {
        this.put(WebResponseCode.KEY_DATA, data);
        return this;
    }

    public WebResponse with(Object key, Object value) {
        this.put(key, value);
        return this;
    }
}
